package com.yhb.controller;

import com.yhb.model.MQMessage;
import com.yhb.model.mq.SumUpParam;
import com.yhb.service.MQService;
import com.yhb.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/settle")
public class SettleController {
    @Qualifier("msgListener")
    @Autowired
    MQService mqService;
    @GetMapping("/startCalculateSplittings")
    public String startCalculateSplittings(){

        String monthString = DateUtils.getLastMonthString();

        MQMessage mqMessage = MQMessage.builder()
                .type(MQMessage.T_START_CALC_SPLITTINGS)
                .content(SumUpParam.builder()
                        .monthString(monthString)
                        .build())
                .build();

        mqService.sendMsg(mqMessage);
        return monthString;
    }
    @GetMapping("/startOutputIncomeReport")
    public String startOutputIncomeReport(){

        String monthString = DateUtils.getLastMonthString();

        MQMessage mqMessage = MQMessage.builder()
                .type(MQMessage.T_START_OUTPUT_INCOME_REPORT)
                .content(SumUpParam.builder()
                        .monthString(monthString)
                        .build())
                .build();

        mqService.sendMsg(mqMessage);
        return monthString;
    }
    @GetMapping("/startOutputIncomeSummaryReport")
    public String startOutputIncomeSummaryReport(){

        String monthString = DateUtils.getLastMonthString();

        MQMessage mqMessage = MQMessage.builder()
                .type(MQMessage.T_START_OUTPUT_INCOME_SUMMARY_REPORT)
                .content(SumUpParam.builder()
                        .monthString(monthString)
                        .build())
                .build();

        mqService.sendMsg(mqMessage);
        return monthString;
    }
}
